<template>
	<view>
		<view class="header status_bar" :class="scrrol == true ? 'scrrolHeader' : ''">
			<view class="text" :class="scrrol == true ? 'scrrolHeader' : ''">{{Lang.lang('首頁')}}</view>
			<!-- 	<view class="link_box">
				<input disabled="ture" type="text" value="" placeholder="鏈接錢包" placeholder-style="color:#fff;"
					v-model="link" />
				<view class="copy iconfont icon-fuzhi" @tap="copyText"></view>
			</view> -->
			<view class="message iconfont icon-tongzhi" data-url="/pages/index/tidings" @click="gotopage">
				<view class="round" v-if="is_message_read==1"></view>
			</view>
			<picker @change="choiceLang" :value="langIndex" :range="Lang.lang('langData')" :range-key="'name'">
				<view class="language" v-if="lang == 'en'">EN</view>
				<view class="language" v-else>CN</view>
			</picker>
		</view>
		<view class="clear_box"></view>

		<view class="page_content">

			<swiper class="swiper_box" :autoplay="true" :interval="3000" :duration="200" indicator-dots="true"
				indicator-color="rgba(255, 255, 255, .5)" indicator-active-color="#fff">
				<block v-for="(item, index) in banner" :key="index">
					<swiper-item style="height: 100%;" :data-url="item.url" @click="gotopage">
						<view class="swiper-item" style="height: 100%;">
							<image :src="item.url" mode="scaleToFill"></image>
						</view>
					</swiper-item>
				</block>
			</swiper>

			<view class="other_max">
				<image class="bg01" src="../../static/bg01.png" mode="widthFix"></image>
				<view class="other_content">
					<view class="other_box">
						<view class="text_box">
							<view class="title">{{Lang.lang('當前總質押')}} (YYKR)</view>
							<view class="num">{{zy_data.zy_yydm_num}}</view>
						</view>
						<view class="icon">
							<image src="../../static/menu/menu01.png" mode="widthFix"></image>
						</view>
					</view>
					<view class="other_box">
						<view class="text_box">
							<view class="title">{{Lang.lang('當前總價值')}} (USDT)</view>
							<view class="num">{{zy_data.zy_yydm_price}}</view>
						</view>
						<view class="icon">
							<image src="../../static/menu/menu02.png" mode="widthFix"></image>
						</view>
					</view>
					<view class="other_box">
						<view class="text_box">
							<view class="title">{{Lang.lang('當前總獎勵')}} (YYKR)</view>
							<view class="num">{{zy_data.zy_yydz_price}}</view>
						</view>
						<view class="icon">
							<image src="../../static/menu/menu03.png" mode="widthFix"></image>
						</view>
					</view>
				</view>
			</view>

			<view class="nav">
				<block v-for="(item, index) in menus" :key="'menus' + index">
					<view class="menu" :data-type="item.type" :data-url="item.url" @click="gotopage03">
						<image :src="item.img" mode="widthFix"></image>
						<view class="text" v-if="lang == 'tc'">{{ item.text_tc }}</view>
						<view class="text" v-if="lang == 'en'">{{ item.text_en }}</view>
					</view>
				</block>
			</view>

			<view class="swiper_box02">
				<view class="notice">
					<view class="icon_box">
						<view class="icon iconfont icon-gonggao"></view>
					</view>
					<swiper class="swiper_box03" :autoplay="true" :interval="3000" :duration="1000" vertical="true">
						<block v-for="(item, index) in notice" :key="index">
							<swiper-item style="height: 100%;" :data-url="'/pages/index/notice'" @click="gotopage">
								<view class="content_text">{{ item.title }}</view>
							</swiper-item>
						</block>
					</swiper>
					<view class="more iconfont icon-T_shangjiantou_sjt" data-url="/pages/index/notice"
						@click="gotopage"></view>
				</view>
			</view>

			<view class="page_title">
				<view class="title">{{Lang.lang('購買')}} YYDM</view>
				<!-- <view class="arrow iconfont icon-T_shangjiantou_sjt" :data-url="'/pages/index/week?go=' + 1" @click="gotopage"></view> -->
			</view>

			<view class="records_box">
				<block v-for="(item, index) in coin_sell" :key="index">
					<view class="records_list">
						<view class="list">
							<view class="title">
								<!-- <view class="i">
									<image src="../../static/cp01.png" mode="widthFix"></image>
								</view> -->
								<view class="t">{{Lang.lang('數量')}}: {{item.sell_num}}</view>

							</view>
							<view class="time">{{item.add_time}}</view>
						</view>
						<view class="list">
							<view class="text">{{Lang.lang('出售價格')}}：{{item.sell_total_price}} USDT</view>
							<view class="menu" @click="autoPupu(item.id)">{{Lang.lang('購買')}}</view>
						</view>
					</view>
				</block>
			</view>

		</view>




		<!-- 输入安全码 -->
		<view class="pupu_box" v-if="pupu" @tap="autoPupu">
			<view class="show_box" @tap.stop="">
				<view class="title">{{Lang.lang('請輸入交易密碼')}}</view>
				<view class="input">
					<input type="password" v-model="pay_password" :placeholder="Lang.lang('請輸入交易密碼')" />
				</view>
				<view class="menu_box">
					<view class="menu" @tap="autoPupu">{{Lang.lang('取消')}}</view>
					<view class="menu" @click="otcYydmBuy">{{Lang.lang('確定')}}</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				lang: 'en',
				langIndex: '',
				link: '',
				pupu: false,
				scrrol: false,
				info: '',
				zy_data: {
					zy_yydm_num: 0,
					zy_yydm_price: 0,
					zy_yydz_price: 0
				},
				banner: [],
				notice: [],
				coin_sell: [],
				is_message_read: 0,
				menus: [{
						img: '../../static/menu/menu04.png',
						text_tc: '資産',
						text_en: 'assets',
						url: '/pages/personalcenter/assets',
						type: '0',
					},
					{
						img: '../../static/menu/menu05.png',
						text_tc: '團隊',
						text_en: 'team',
						url: '/pages/personalcenter/team',
						type: '0',
					},
					{
						img: '../../static/menu/menu06.png',
						text_tc: '商城',
						text_en: 'mall',
						url: '/pages/mall/mall',
						type: '0',
					},
					{
						img: '../../static/menu/menu07.png',
						text_tc: '競猜',
						text_en: 'guessing',
						url: '/pages/guess/guess',
						type: '1',
					},
				],
				page: 0,
				pay_password: '',
				buy_id: 0
			}
		},
		onLoad() {

		},
		onShow() {
			this.setMenuLang();
			this.lang = uni.getStorageSync('_language');
			this.loadData();
		},
		methods: {
			setMenuLang() {
				let that = this;
				uni.setTabBarItem(this.Lang.lang('indexMenu')[0]);
				uni.setTabBarItem(this.Lang.lang('indexMenu')[1]);
				uni.setTabBarItem(this.Lang.lang('indexMenu')[2]);
				uni.setTabBarItem(this.Lang.lang('indexMenu')[3]);
				uni.setTabBarItem(this.Lang.lang('indexMenu')[4]);
			},
			choiceLang: function(e) {
				let that = this;
				that.langIndex = e.target.value
				let lang = that.Lang.lang('langData')[that.langIndex].type;
				that.lang = lang;
				uni.setStorageSync('_language', lang);
				// that.setMenuLang();
				location.reload()
			},
			autoPupu(buy_id) {
				let that = this;
				that.pay_password = '';
				that.pupu = !that.pupu;
				that.buy_id = buy_id
			},
			loadData() {
				let that = this;
				that.page = 0;
				that.coin_sell = [];
				that.loadPageData();
			},
			loadPageData() {
				let that = this;
				that.page++;
				that.Net._get('api/index/main', {
					page: that.page
				}, res => {
					if (res.code == 200) {
						that.banner = res.data.banner
						that.notice = res.data.notice
						that.zy_data = res.data.zy_data
						that.coin_sell = that.coin_sell.concat(res.data.coin_sell); //将数据拼接在一起
						that.is_message_read = res.data.is_message_read
					}
				});
			},
			otcYydmBuy() {
				let that = this
				that.Net._get('api/wallet/otcYydmBuy', {
					id: that.buy_id,
					pay_password: that.pay_password
				}, res => {
					if (res.code == 200) {
						that.Msg.Success(res.msg)
						that.pupu = false
						setTimeout(function() {
							that.loadData()
						}, 500)
					}
				});
			},
			backPage() {
				uni.navigateBack({});
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: url
				});
			},
			gotopage03(e) {
				let url = e.currentTarget.dataset.url;
				let type = e.currentTarget.dataset.type;
				if (type == 0) {
					uni.navigateTo({
						url: url
					});
				} else if (type == 1) {
					uni.switchTab({
						url: url
					});
				}
			}
		},
		onPageScroll: function(Object) {
			//console.log(Object.scrollTop); //实时获取到滚动的值
			if (Object.scrollTop > 28) {
				this.scrrol = true;
				/* #ifdef APP-PLUS */
				/* #endif */
			} else if (Object.scrollTop < 28) {
				this.scrrol = false;
				/* #ifdef APP-PLUS */
				/* #endif */
			}
		},
		onReachBottom() {
			let that = this;
			that.loadPageData()
		},
	}
</script>

<style>
	.scrrolHeader {
		width: 100%;
		background-color: #1A1A1A !important;

	}

	.page_content {
		width: 92%;
		margin: 0 auto;
	}

	.swiper_box {
		width: 100%;
	}

	.swiper_box image {
		width: 100%;
		border-radius: 3vw;
	}

	.other_max {
		width: 100%;
		background-color: #090909;
		position: relative;
	}

	.other_max .bg01 {
		width: 100%;
	}

	.other_max .other_content {
		width: 100%;
		position: absolute;
		left: 0;
		top: 0;
		padding: 2% 4%;
	}

	.other_box {
		width: 100%;
		border-radius: 4vw;
		margin-top: 4%;
		display: flex;
		align-items: center;
	}

	.other_box .icon {
		width: 15vw;
		margin-left: 3vw;
	}

	.other_box .icon image {
		width: 100%;
		display: block;
	}

	.other_box .text_box {
		flex: 1;
	}

	.other_box .text_box .title {
		font-size: 3.2vw;
		color: #999999;
	}

	.other_box .text_box .num {
		font-size: 5.5vw;
		color: #fff;
		margin-top: 1vw;
		font-weight: bold;
	}

	.nav {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 4%;
	}


	.nav .menu {
		text-align: center;
	}

	.nav .menu image {
		width: 16vw !important;
		height: 16vw !important;
		border: 50%;
	}

	.nav .menu .text {
		width: 100%;
		text-align: center;
		font-size: 3.5vw;
		color: #fff;
		margin-top: 1vw;
	}

	.swiper_box02 .more {
		font-size: 4.5vw;
		color: #6B6B6B;
		height: 100%;
		width: 13vw;
		display: flex;
		align-items: center;
		justify-content: center;

	}

	.swiper_box03 {
		width: 80%;
		height: 10.5vw;
	}

	.swiper_box02 {
		width: 100%;
		margin: 0 auto;
		height: 12vw;
		margin: 4vw auto;
		position: relative;
		background-color: #1A1A1A;
		box-sizing: border-box;
		border-radius: 2vw;
		box-sizing: border-box;
	}

	.swiper_box02 .notice {
		width: 100%;
		height: 12vw;
		display: flex;
	}

	.swiper_box02 .notice .icon_box {
		display: flex;
		justify-content: center;
		margin-left: 4%;
		margin-right: 2vw;
	}

	.swiper_box02 .notice .icon_box .icon {
		font-size: 6vw;
		color: #0155FF;
		line-height: 12vw;
		margin-right: 1vw;
	}

	.swiper_box02 .notice .icon_box .text {
		font-size: 4vw;
		color: #fff;
		line-height: 10.5vw;
		font-weight: bold;
	}

	.swiper_box02 .notice .content_text {
		font-size: 3.8vw;
		color: #fff;
		line-height: 12vw;
		flex: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.page_title {
		width: 100%;
		display: flex;
		align-items: center;
		margin-top: 4vw;
	}

	.page_title .title {
		font-size: 4.5vw;
		color: #fff;
		font-weight: bold;
		flex: 1;
	}

	.page_title .arrow {
		display: flex;
		align-items: center;
		font-size: 4vw;
		color: #fff;
	}

	.records_box {
		width: 100%;
		margin-top: 4vw;
	}

	.records_box .records_list {
		width: 100%;
		background-color: #2B2B2B;
		padding: 4%;
		position: relative;
		border-radius: 3vw;
		margin-bottom: 4vw;
	}

	.records_box .records_list .list {
		width: 100%;
		display: flex;
		align-items: center;

	}

	.records_box .records_list .list:nth-child(2) {
		margin-top: 4vw;
	}

	.records_box .records_list .list .title {
		flex: 1;
		display: flex;
		align-items: center;
	}

	.records_box .records_list .list .title .t {
		font-size: 5vw;
		color: #fff;
		margin-left: 2vw;
		font-weight: bold;
	}

	.records_box .records_list .list .title .i {
		width: 8vw;
	}

	.records_box .records_list .list .title .i image {
		width: 100%;
		display: block;
	}

	.records_box .records_list .list .time {
		font-size: 3.2vw;
		color: #919191;
	}

	.records_box .records_list .list .text {
		font-size: 3.8vw;
		color: #fff;
		flex: 1;
	}

	.records_box .records_list .list .menu {
		font-size: 3.5vw;
		background-color: #0155FF;
		height: 8vw;
		line-height: 8vw;
		border-radius: 2vw;
		padding: 0 4vw;
		color: #fff;
	}

	/*  */
	.pupu_box {
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.7);
		position: fixed;
		left: 0;
		top: 0;
		z-index: 999;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.pupu_box .show_box {
		width: 70%;
		background-color: #2B2B2B;
		border-radius: 3vw;
		padding: 5vw 0 0 0;
		position: relative;
	}

	.pupu_box .show_box .title {
		width: 100%;
		text-align: center;
		font-size: 4vw;
		color: #fff;
		font-weight: bold;
		margin-bottom: 5vw;
	}

	.pupu_box .show_box .input {
		width: 84%;
		margin: 0 auto;
		background-color: #222222;
		border-radius: 2vw;
	}

	.pupu_box .show_box .input input {
		width: 100%;
		height: 12vw;
		line-height: 12vw;
		font-size: 3.5vw;
		color: #fff;
		text-align: center;
	}

	.pupu_box .show_box .menu_box {
		width: 100%;
		display: flex;
		align-items: center;
		margin-top: 5vw;
	}

	.pupu_box .show_box .menu_box .menu {
		flex: 1;
		height: 12vw;
		line-height: 12vw;
		font-size: 3.8vw;
		text-align: center;
	}

	.pupu_box .show_box .menu_box .menu:nth-child(1) {
		border-radius: 0 0 0 3vw;
		background-color: #414141;
		color: #fff;

	}

	.pupu_box .show_box .menu_box .menu:nth-child(2) {
		border-radius: 0 0 3vw 0;
		color: #fff;
		background-color: #0155FF;
	}

	/*  */
</style>